package com.itheima.test;

import org.junit.Test;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class demo {
    public static void main(String[] args) {
        for (String arg : args) {
            System.out.println(arg);
        }
       // System.out.println(args);
    }

    @Test
    public void test1(){
       /* String[] args = {"vfs","fewrf","ferf","fwefr","geer","erfrew"};
        main(args);
        System.out.println("..................");
*/
        test2 t1 = new test3();

        test2 t2 = (test2) Proxy.newProxyInstance(t1.getClass().getClassLoader(), new Class[]{test2.class}, new InvocationHandler() {
            @Override
            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                if (method.getName().equals("study")){
                    System.out.println("写字");
                    return method.invoke(t1, args);
                }else{
                    return method.invoke(t1, args);
                }

            }
        });

        t2.study();

    }
}
interface test2{
    void study();
}

class test3 implements test2{

    @Override
    public void study() {
        System.out.println("看书");
    }
}